﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Enter.Mvc.Base.Controllers;
using Enter.Services.DataCache;
using Enter.Services.Mail;
using System.Web.Mvc;
using Enter.Mvc.Mall.Model.Shop;
using Enter.Mvc.Mall.Model;
using Enter.Entity;
using Enter.Mvc.Mall.Model.User;
using Enter.Mvc.Mall.Model.Product;
using Enter.Config;

namespace Enter.Mvc.Mall.Controllers
{
    public class ShopController : BaseControllers
    {
             private readonly ICache icache;
        private readonly IMail imail;

        public ShopController(ICache cache, IMail mail)
        {
            this.icache = cache;
            this.imail = mail;
        }
        #region 开店
        public ActionResult openShop()
        {
            return View();
        }
        public ActionResult openShopBasic()
        {
          
            return View();
        }
        [HttpPost]
        [ValidateInput(false)]
        public ActionResult openShopBasic(OpenShopModel Model)
        {
        
            var results = new JsonResultModel();
            try
            {
                T401_ShopEntity entity=new T401_ShopEntity();
                T402_ShopInfoEntity entityinfo=new T402_ShopInfoEntity();

                entity.SNo=imail.GetShopNo();
                entity.SName=Model.SName;
                entity.UIID=UserInfo.CurrentUser.UserID;
                entity.SLogo=Model.SLogo;
                entityinfo.SNo = entity.SNo;
                entity.SType = Model.SType.ToString();
                entityinfo.STag = Model.STag;
                entityinfo.Memo=Model.Memo;
                entityinfo.SAdress=Model.SAdress;
                imail.AddShop(entity, entityinfo);
            }
            catch (Exception ex)
            {
                
                results.ResultCode = "01";
                results.ResultMsg = ex.Message;
            }
            results.ResultCode = "01";
            results.ResultMsg = Model.Memo;
            return Json(results);
        }

        #endregion

#region 店铺页面

        public ActionResult ShopNav()
        {
            return View();
        }
        public ActionResult HotProductsRank(string shopNo)
        {

            int count=10;
           List<T101_GoodsEntity> collectList=imail.GetCollectGoodsbyShop(shopNo, count);
           List<T101_GoodsEntity> hotList = imail.GetHotGoodsbyShop(shopNo, count);

           List<ProductModel> collect = new List<ProductModel>();
           List<ProductModel> hot = new List<ProductModel>();

           if (collectList != null)
           {
               foreach (T101_GoodsEntity entity in collectList)
               {
                   ProductModel model = new ProductModel();
                   model.GID = entity.GID;
                   model.SalePRICE = entity.GSalePRICE;
                   model.Title = entity.GTitle;
                   model.ImgUrl =ImgPathConfig.productInfoServerPath+ entity.ImgUrl;
                   model.CollectCount = entity.CollectCount;
                   collect.Add(model);
               }
           }
           if (hot != null)
           {
               foreach (T101_GoodsEntity entity in hotList)
               {
                   ProductModel model = new ProductModel();
                   model.GID = entity.GID;
                   model.SalePRICE = entity.GSalePRICE;
                   model.Title = entity.GTitle;
                   model.ImgUrl =ImgPathConfig.productInfoServerPath+ entity.ImgUrl;
                   model.SaleCount = entity.SaleCount;
                   hot.Add(model);
               }
           }

           IDictionary<string, object> test = new Dictionary<string, object>();
           test.Add("collect", collect);
           test.Add("hot", hot);
           return PartialView(test);
        }
#endregion
        
    }
}
